package br.com.teste;




import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.view.MotionEvent;
import android.view.View;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;

public class TesteMovimentoImagensActivity extends Activity{
    /** Called when the activity is first created. */
	

    ImageView image;
    ProgressBar barra;
    TextView timer;
    
    
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        
        image = (ImageView) findViewById(R.id.image);
        barra = (ProgressBar) findViewById(R.id.progressBar);
        timer = (TextView) findViewById(R.id.Timer);
        
        image.setImageResource(R.drawable.apple);
       
        final CountDownTimer Contar = new CountDownTimer(10000, 100) {
    	   
    	   public void onFinish() {
    		    timer.setText("Finished!");
    		    startActivity(new Intent(TesteMovimentoImagensActivity.this, TelaPerdedor.class));
    	   }
    	   public void onTick(long millisUntilFinished) {
    		 
    		   timer.setText("Contagem em Milissegundos: " + String.valueOf(millisUntilFinished));
//    		    String Segundos = String.valueOf(millisUntilFinished);
//    		    Segundos = Segundos.substring(0, 2);
//    		    timer.setText(""+Segundos);
    		   }
    	   
    	  
    		         
    		        };
    		        Contar.start();
    		    

        
        
        image.setOnTouchListener(new View.OnTouchListener() {
			
			public boolean onTouch(View v, MotionEvent event) {
				
				 int action = event.getAction();
				 switch (action) {
				 case MotionEvent.ACTION_UP:
					 image.setImageResource(R.drawable.horse);
					 break;
				 case MotionEvent.ACTION_DOWN:
					 image.setImageResource(R.drawable.apple);
					 barra.incrementProgressBy(10);
					 barra.setMax(100);
					 if(barra.getProgress()==100){
				   		 Toast.makeText(TesteMovimentoImagensActivity.this, "Chegou no Final", Toast.LENGTH_SHORT).show();
				   		Contar.cancel();
				   		 startActivity(new Intent(TesteMovimentoImagensActivity.this, Ganhou.class));
				   	 }
					 
					 break;
					 
				 default:
				      break;
					 
				 }

			
				
				
				return true;
			}
		});
        

    }
    
    

	
}